﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ViewMove : MonoBehaviour {
    private float MX, MY;//鼠标移动值
    public float MS;//鼠标灵敏度
    public Transform player;//玩家位置
    public float XR;//鼠标旋转
    private void Update()
    {
        MX = Input.GetAxis("Mouse X") * MS * Time.deltaTime;
        MY = Input.GetAxis("Mouse Y") * MS * Time.deltaTime;
        XR -= MY;
        XR = Mathf.Clamp(XR, -50f, 40f);
        player.Rotate(Vector3.up * MX);//玩家左右视角移动
        transform.localRotation = Quaternion.Euler (XR, 0, 0);//上下视角移动
        if (Input.GetMouseButtonDown(0))//鼠标锁定
        {
            Cursor.lockState = CursorLockMode.Locked;
        }
        if (Input.GetMouseButtonDown(1))//鼠标解锁
        {
            Cursor.lockState = CursorLockMode.None;
        }
    }
}
